home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11373 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: ix.netcom.com!news
  2. From: Henry Cross <hcross@ix.netcom.com>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Speed of C program vs. Speed of Pascal program
  5. Date: Wed, 13 Mar 1996 19:44:31 -0800
  6. Organization: i586 Box @Irvine, Ca.
  7. Message-ID: <3147961F.420@ix.netcom.com>
  8. References: <4hsf8p$c5d@caesar.ultra.net> <4hum94$npg@challenge.tcel.com>
  9. NNTP-Posting-Host: irv-ca12-23.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-NETCOM-Date: Wed Mar 13  9:45:45 PM CST 1996
  14. X-Mailer: Mozilla 2.0 (Win95; I)
  15.  
  16. Ritchie Annand wrote:
  17. > In article <4hsf8p$c5d@caesar.ultra.net>,
  18. >    kbrady@ultranet.com (Ken Brady) wrote:
  19. > >I recently began learning to program in C/C++ after many years
  20. > >of using Borland Turbo Pascal (v6.0).  I have been porting a data analysis
  21. > >program into C/C++, and notice that a subroutinefor reading large tables of
  22. > >numbers (ASCII) and loading these numbers into (binary) arrays proceeds much
  23. > >more rapidly in my C program than in my Pascal program.  For one large
  24. > table,
  25. > >my Pascal program requires about 10 s to load the table, while the C program
  26. > >loads it in less than 1 second.
  27. > >
  28. > >The I/O algorithms in these programs are essentially identical.  I deduce
  29. > >that the C atof function is much faster than the Pascal Val function.  Is
  30. > >this typical?
  31. > >
  32. > >My C/C++ compiler is Watcom 10.5, running under OS/2.
  33. > Actually, that depends...
  34. > It's quite possible atof is faster than Val - they are both library
  35. > functions, after all, but generally speaking, you won't get a 10:1 speed ramp
  36. > between the two from that sort of difference.
  37. > It'd be my guess that you're using unbuffered Pascal I/O versus buffered C
  38. > I/O... I've found that to be where most file-access differences lie:
  39. > If your Pascal program uses:
  40. > var
  41. >   f : Text;
  42. > Then it's buffered (but not with a very large buffer - you can set it,
  43. > though)
  44. > If you use:
  45. > var
  46. >   f : File;
  47. > or
  48. >   f : File of Char;
  49. > or
  50. >   f : File of MyRecord;
  51. > Then it's unbuffered.
  52. > With f : File, though, you do have the option of doing BlockRead and
  53. > BlockWrite.  Reset(f,SizeOf(MyRecord)) - if you're using a flat file of
  54. > MyRecords, and BlockRead(f,MyRecordArray,NumberOfRecords,ActualRecordsRead) -
  55. > that will give you some mighty good throughput ;)
  56.  
  57.   So will setvbuff() :)
  58.  
  59. regards,
  60. H.Cross
  61. hcross@ix.netcom.com
  62.